/**
 * @version 3 11 February 2013
 * @author Myhaylo Kotsyuruba
 */

public class OneCorrectAnswerQuestions extends ManyAnswersQuestions {
    
    public OneCorrectAnswerQuestions(String text, int score, Answer[] answers) {
        super(text, score, answers);
    }

    @Override
    public AnswerMap convertsUserAnswer(String userAnswer) {
        AnswerMap userAnswerMap = new AnswerMap(1);
        int numberAnswer = Integer.parseInt(userAnswer);
        userAnswerMap.setField(0, numberAnswer);
        return userAnswerMap;
    }

    @Override
    public AnswerMap getCorrectAnswerMap() {
        AnswerMap correctAnswerMap = new AnswerMap(1);
        for (int index = 0; index < getQuantityAnswers(); index++) {
            if (isCorrectAnswer(index)) {
                int numberAnswer = index + 1;
                correctAnswerMap.setField(0, numberAnswer);
                break;
            }
        }
        return correctAnswerMap;
    }

    @Override
    public Question clone() {
        
        return new OneCorrectAnswerQuestions(getText(), getScore(),
                getAnswers());
    }
    
    @Override
    public String toString() {
        String result = String.format("%s%nPlease, enter number of correct "
                + "answer.", super.toString());
        return result;
    }
}
